package com.yjs.ppjokedemo.repo;

import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;

import com.yjs.ppjokedemo.bean.LikedItem;
import com.yjs.ppjokedemo.bean.RecomProduct;

import java.util.ArrayList;
import java.util.List;

public class LikedRepo {

    private MutableLiveData<List<LikedItem>> mMutableLiveData = new MutableLiveData<>();

    public LiveData<List<LikedItem>> getLiked(){
        if (mMutableLiveData.getValue() == null){
            initLiked();
        }
        return mMutableLiveData;
    }

    private void initLiked() {
        mMutableLiveData.setValue(new ArrayList<>());
    }

    public boolean addItemToLiked(RecomProduct recomProduct){
        if (mMutableLiveData.getValue() == null){
            initLiked();
        }

        List<LikedItem> likedItemList = new ArrayList<>(mMutableLiveData.getValue());

        mMutableLiveData.setValue(likedItemList);
        return true;
    }
}
